//
//  WBTitleButton.swift
//  SwiftWeibo
//
//  Created by Lausen on 2017/4/21.
//  Copyright © 2017年 id. All rights reserved.
//

import UIKit

class WBTitleButton: UIButton {

    var count: Int64 = 0
    
    
    init(title: String?) {
        super.init(frame: CGRect())
        
        if title == nil {
            
            setTitle("首页", for: [])
        }else{
            
            setTitle(title! + " ", for: [])
            
            setImage(UIImage(named: "navigationbar_arrow_down"), for: .normal)
            setImage(UIImage(named: "navigationbar_arrow_up"), for: .selected)
        }
        
        titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
        setTitleColor(UIColor.darkGray, for: [])
    
        
        sizeToFit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    /// 重新布局了一次子视图
    override func layoutSubviews() {
        super.layoutSubviews()
        
        guard let titleLabel = titleLabel,
            let imageView = imageView else{
                
                return
        }
        
        /*
         OC中不允许修改结构体的值,
         Swift中可以直接修改
         */
        titleLabel.frame.origin.x = 0
        imageView.frame.origin.x = titleLabel.bounds.width
    }
}
